<?php

namespace app\index\controller;


use app\admin\model\Menu as MenuModel;
use app\operation\model\ArticleColumn;

use think\Controller;

class Index extends Controller
{
    public function test()
    {
        $ids = [];
        $menus = MenuModel::where('pid', 0)->select();
        foreach ($menus as $menu) {
            array_push($ids, $menu['id']);
            $this->recursionSetStatus($menu,$ids);
        }
        MenuModel::where('id', 'not in', $ids)->delete();
    }

    private function recursionSetStatus($menu, &$ids)
    {
        if ($menu['status'] == 0) {
            MenuModel::where('pid', $menu['id'])->setField('status', 0);
        }
        $sons = MenuModel::where('pid', $menu['id'])->select();
        if (!$sons) return;
        foreach ($sons as $son) {
            array_push($ids, $son['id']);
            $this->recursionSetStatus($son,$ids);
        }
    }
    public function expore_area()
    {        
        \app\common\model\Area::getJs();
    }


    //渲染官网首页
    public function index()
    {    
        //视图根目录开始读取模板
        return view('/index/index');
        //return redirect('/admin');//跳转后台
    }

    //服务协议
    public function service()
    {
        $content = ArticleColumn::where('id', 1)->value('content');
        $this->assign('content', $content);
        return $this->fetch();
    }

    //隐私政策
    public function privacy_policy()
    {
        $content = ArticleColumn::where('id', 2)->value('content');
        $this->assign('content', $content);
        return $this->fetch();
    }
    //订单自动定时任务url执行方式已转移到order模块下controller目录的Timing控制器中(app\order\controller\Timing)
    //也可以用命令行模式执行 参考application/command.php
    //修改任务到order/event目录下修改对应钩子即可
}
